<?php
class Add_user extends CI_Controller{
    
    public function __construct(){
        parent::__construct();        
        $this->load->model('user_model');
    }
    public function create(){
       $this->form_validation->set_rules(
            array(
                array(
                    'field' => 'user_name', 
                    'label' => 'user_name', 
                    'rules' => 'trim|required'
                    ),
                array('field' => 'user_email', 'label' => 'Email', 'rules' => 'trim|required|valid_email|callback_email_check'),
                array(
                    'field' => 'user_password', 
                    'label' => 'user_password', 
                    'rules' => 'trim|required'
                    )
               ));
              
       if ($this->form_validation->run() == FALSE)	 {        
             $data['main_content']='add_user';     
             $cond['user_category_deleted']=0;
             $data['user_category']=$this->user_model->get_user_category($cond)->result();       
             $this->load->view('ship_template',$data);   
               	 
		}else  
        {    
            $input_data['user_email']=$this->input->post('user_email')  ;
            $input_data['user_password']=md5($this->input->post('user_password') ) ;
            $input_data['user_name']=$this->input->post('user_name')  ;
            $input_data['user_address']=$this->input->post('user_address')  ; 
            $input_data['user_category_id']=$this->input->post('user_category_id')  ;
            $input_data['organisation_name']=$this->input->post('organisation_name')  ;                        
            $input_data['user_phone']=$this->input->post('user_phone')  ;            
            $this->user_model->create($input_data);
            
             $this->list_user();
        }          
    } 
    
    public function list_user(){
        $this->session->set_userdata('navigation','List User');
        $cond['user_deleted']=0;
        $data['users_list']=$this->user_model->get_users($cond)->result();
        
        if(count($data['users_list']>0)){
            $data['main_content']='list_user';                
        }else{
            $data['page_title']='User Listing';
            $data['main_content']='no_records'; 
        }
        $this->load->view('ship_template',$data);        
    }
    
} 
?>